/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.java.modules.app.controller;


import com.java.common.utils.R;
import com.java.modules.app.annotation.Login;
import com.java.modules.app.annotation.LoginUser;
import com.java.modules.app.entity.UserEntity;
import com.java.threadPool.service.AsyncTest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * APP测试接口
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/app")
@Api("APP测试接口")
public class AppTestController {

    @Autowired
    private AsyncTest asyncTest;

    @Login
    @GetMapping("userInfo")
    @ApiOperation("获取用户信息")
    public R userInfo(@LoginUser UserEntity user){
        return R.ok().put("user", user);
    }

    @Login
    @GetMapping("userId")
    @ApiOperation("获取用户ID")
    public R userInfo(@RequestAttribute("userId") Integer userId){
        return R.ok().put("userId", userId);
    }

    @GetMapping("notToken")
    @ApiOperation("忽略Token验证测试")
    public R notToken(){
        try {
            Thread.sleep(10000);
            System.out.println(Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return R.ok().put("msg", "无需token也能访问。。。");
    }

    @GetMapping("notToken1")
    @ApiOperation("忽略Token验证测试")
    public R notToken1(){
        System.out.println(Thread.currentThread().getName());
        return R.ok().put("msg", "无需token也能访问。。。");
    }

    @GetMapping("threadTest")
    @ApiOperation("threadTest")
    public R threadTest(){
        for (int i = 0; i < 100; i++) {
            asyncTest.doTest(i);
        }
        return R.ok();
    }

}
